﻿
function goBack() {
    location.href = '/Role/RoleList';
}

function SubData() {
    var pagesCheck=new Array();
    $("#tableCheckBox").find("input[type=checkbox]:checked").each(function () {
        pagesCheck.push($(this).attr("name"));
    })
    var postData = {
        RoleID: $("#hid").val(),
        RoleName: $("#Rolename").val(),
        Description: HtmlUtil.htmlEncodeByRegExp(CKEDITOR.instances.desTextarea.getData()),
        PagesCheck: pagesCheck
    };

    $.ajax({
        type: 'post',
        traditional: true,
        url: '/Role/Updateinfo',
        data: postData,
        success: function (data) {
            if (data == "suc") {
                //关闭层，刷新表单
                goBack();
            }
            else if (data == "repeat") {
                $.alert({
                    title: '系统提示',
                    content: '重复数据无法添加！',
                    confirm: function () {
                    }
                });
            }
            else {
                $.alert({
                    title: '系统提示',
                    content: '重复数据无法添加！',
                    confirm: function () {
                    }
                });
            }
        },
        error: function () {
            $.alert({
                title: '系统提示',
                content: '操作失败！',
                confirm: function () {
                }
            });
        }
    });
}


$(document).ready(function () {
    //初始化左侧菜单
    $("#rightUser").addClass("active");
    CKEDITOR.replace('desTextarea', {
        Rolebar: 'Basic'
        //uiColor: '#9AB8F3'//界面颜色
    });
    CKEDITOR.instances.desTextarea.setData(HtmlUtil.htmlDecodeByRegExp($("#hidDescription").val()));
    //
    $(".checkBoxPageEdit").change(function () {
        if ($(this).prop("checked") == true) {
            $(this).prev().prop("checked", true);
        }
    });
    $('#RoleAddForm')
.bootstrapValidator({
    message: 'This value is not valid',
    feedbackIcons: {
        valid: 'glyphicon glyphicon-ok',
        invalid: 'glyphicon glyphicon-remove',
        validating: 'glyphicon glyphicon-refresh'
    },
    fields: {
        Rolename: {
            message: 'The Role Name is not valid',
            validators: {
                notEmpty: {
                    message: 'The Role Name is required and can\'t be empty'
                }
            }
        }
    }
})
.on('success.form.bv', function (e) {
    e.preventDefault();
    SubData();
});
});
